<?php

class Vlib_Config {
    /** config key name */

    const KEY = "Vlib_config_";

    /**
     * @desc Get application config file
     * 
     * @author Tuyendn<tuyendn@vnext.vn>, trunghpb@vnext.vn
     * @since 2011/12/17
     * */
    public static function getConfig() {
        $_key = self::KEY; // . $_host;
        if (isset($_SERVER['SERVER_NAME'])) {
            $_host = $_SERVER['SERVER_NAME'];
            $_host = (substr($_host, 0, 3) == 'www') ? substr($_host, 4) : $_host;
            if (!Zend_Registry::isRegistered($_key)) {
                // get the host config file name
                $_hostConfig = APPLICATION_PATH . DS . 'configs' . DS . $_host . '.php';
            }
        }
        // get the default config file name
        $_defaultConfig = APPLICATION_PATH . DS . 'configs' . DS . 'application.php';

        // using default config fiel if host config file is not exists
        $_configFile = @file_exists($_hostConfig) ? $_hostConfig : $_defaultConfig;
        if (file_exists($_configFile)) {
            include $_configFile;
            // register config object
            Zend_Registry::set($_key, $config);
        } else {
            return null;
        }
        //var_dump(Zend_Registry::get($_key));
        return Zend_Registry::get($_key);
    }

    public static function getTempConfig() {
        $_moduleDir = APPLICATION_PATH . DS . 'modules';
        // get the default config file name
        $_defaultConfig = $_moduleDir . DS . 'install' . DS . 'config' . DS . 'application.install.php';
        include $_defaultConfig;
        return $config;
    }

}